package com.example.springtransdemo.Service;

import com.example.springtransdemo.Mapper.LogInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper;
//    @Transactional(propagation = Propagation.REQUIRED)
//    public void insertLog(String username, String password) {
//        logInfoMapper.insertLog(username,password);
//    }
//@Transactional(propagation = Propagation.REQUIRES_NEW)
//public void insertLog(String username, String password) {
//    logInfoMapper.insertLog(username,password);
//    int a=10/0;
//}
//@Transactional(propagation = Propagation.NEVER)
//public void insertLog(String username, String password) {
//    logInfoMapper.insertLog(username,password);
//}
@Transactional(propagation = Propagation.NESTED)
public void insertLog(String username, String password) {
    logInfoMapper.insertLog(username,password);
    try{
        int a=10/0;
    }catch (Exception e){
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
    }
}
}
